package api.login;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;

public class LogoutServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        退出登录，就是删除session（本质就是删除session里面的键），让浏览器转向登录页面
        HttpSession session=request.getSession();
        response.setContentType("text/html;charset=utf-8");
        Object user=session.getAttribute("user");
        if(user!=null) session.removeAttribute("user");
        response.getWriter().write("退出登录成功！三秒后转向登录页面");
        response.setHeader("Refresh","3;URL=/login.html");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
